From b2538b1c499ba6f532e2c4dd9e062c6f90053832 Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Sun, 27 Nov 2005 01:06:20 +0000 Subject: [PATCH] Change the console handling, to remove the loop and timeout if a console fails to respond first time. For restored and unpaused domains there is no need for the console to output data, so we cannot use this as a way to detect the liveness of a console. Instead, a command must always be sent to the console, which means that this failure can only be detected once the constructor of the Console class has returned successfully. The __chewall loop still remains, in order to detect runaway consoles and to clear out previous data from the console before executing commands, but we no longer treat failure of that method to read data as a failure of the console itself. Signed-off-by: Ewan Mellor --- tools/xm-test/lib/XmTestLib/Console.py | 43 +++++++------------ .../tests/restore/01_restore_basic_pos.py | 3 ++ .../tests/unpause/01_unpause_basic_pos.py | 3 -- 3 files changed, 19 insertions(+), 30 deletions(-) diff --git a/tools/xm-test/lib/XmTestLib/Console.py b/tools/xm-test/lib/XmTestLib/Console.py index f502adc859..33455ef047 100755 --- a/tools/xm-test/lib/XmTestLib/Console.py +++ b/tools/xm-test/lib/XmTestLib/Console.py @@ -66,37 +66,25 @@ class XmConsole: self.historySaveCmds = historySaveCmds self.debugMe = False self.limit = None - self.delay = 2 consoleCmd = ["/usr/sbin/xm", "xm", "console", domain] - start = time.time() - - while (time.time() - start) < self.TIMEOUT: - if verbose: - print "Console executing: %s" % str(consoleCmd) + if verbose: + print "Console executing: %s" % str(consoleCmd) - pid, fd = pty.fork() + pid, fd = pty.fork() - if pid == 0: - os.execvp("/usr/sbin/xm", consoleCmd[1:]) + if pid == 0: + os.execvp("/usr/sbin/xm", consoleCmd[1:]) - self.consolePid = pid - self.consoleFd = fd + self.consolePid = pid + self.consoleFd = fd - tty.setraw(self.consoleFd, termios.TCSANOW) - - bytes = self.__chewall(self.consoleFd) + tty.setraw(self.consoleFd, termios.TCSANOW) - if bytes > 0: - return + self.__chewall(self.consoleFd) - if verbose: - print "Console didn't attach, waiting %i sec..." % self.delay - time.sleep(self.delay) - raise ConsoleError("Console didn't respond after %i secs" % self.TIMEOUT) - def __addToHistory(self, line): self.historyBuffer.append(line) self.historyLines += 1 @@ -145,8 +133,8 @@ class XmConsole: if self.debugMe: sys.stdout.write(foo) bytes += 1 - except: - timeout += 1 + except Exception, exn: + raise ConsoleError(str(exn)) else: timeout += 1 @@ -174,7 +162,7 @@ class XmConsole: os.write(self.consoleFd, "%s\n" % command) - while 1==1: + while True: i, o, e = select.select([self.consoleFd], [], [], self.TIMEOUT) if self.consoleFd in i: @@ -183,9 +171,10 @@ class XmConsole: if self.debugMe: sys.stdout.write(str) bytes += 1 - except: - raise ConsoleError("Failed to read from console (fd=%i)" - % self.consoleFd) + except Exception, exn: + raise ConsoleError( + "Failed to read from console (fd=%i): %s" % + (self.consoleFd, exn)) else: raise ConsoleError("Timed out waiting for console") diff --git a/tools/xm-test/tests/restore/01_restore_basic_pos.py b/tools/xm-test/tests/restore/01_restore_basic_pos.py index 5241365d49..df9c8018dd 100644 --- a/tools/xm-test/tests/restore/01_restore_basic_pos.py +++ b/tools/xm-test/tests/restore/01_restore_basic_pos.py @@ -63,6 +63,9 @@ if not isDomainRunning(domain.getName()): # Make sure it's alive try: newConsole = XmConsole(domain.getName()) + run = newConsole.runCmd("ls") + if run["return"] != 0: + FAIL("Unable to read from restored domain") except ConsoleError, e: FAIL("Restored domain is dead (%s)" % str(e)) diff --git a/tools/xm-test/tests/unpause/01_unpause_basic_pos.py b/tools/xm-test/tests/unpause/01_unpause_basic_pos.py index 73a4a805c7..d459c6abd1 100644 --- a/tools/xm-test/tests/unpause/01_unpause_basic_pos.py +++ b/tools/xm-test/tests/unpause/01_unpause_basic_pos.py @@ -70,9 +70,6 @@ if status != 0: # Are we still alive after all that? try: console = XmConsole(domain.getName(), historySaveCmds=True) -except ConsoleError, e: - pass -try: run = console.runCmd("ls") except ConsoleError, e: FAIL(str(e)) -- 2.30.2